package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Searchcopy
 */
@WebServlet("/Searchcopy")
public class SearchCopy extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String searchtype = request.getParameter("types3");
		String searchinfo = request.getParameter("searchinfo3");
		if (searchtype == null)
			searchtype = "status";
		if (searchinfo == null)
			searchinfo = "";
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		try {
			Connection con = dbOperator.BasicOperation.getConnection();
			ResultSet rs;
			rs = dbOperator.AdvancedOperation.getSpecificBookInfo(con, searchinfo, searchtype);
			while (rs.next()) {
				out.print("<tr>");
				out.println("<td>" + rs.getString(4) + "</td>");
				String bookID = rs.getString(1);
				out.println(
						"<td><a href='' onclick='gengrateBarcode2(this)' data-toggle='modal' data-target='#codePanel2'>"
								+ bookID + "</a></td>");
				out.print("<td id=\"loc" + bookID + "\">"+rs.getString(2)+"</td>");
				out.print("<td id=\"sta" + bookID + "\">"+rs.getString(3)+"</td>");
				out.print("<td><input type=\"button\" class=\"btn btn-primary\" value=\"edit\" name=\"edt" + bookID
						+ "\" onclick=\"editSpecificBook(this)\" data-toggle='modal' data-target='#editSpecificBook'>");
				out.print("<input type=\"button\" class=\"btn btn-danger\" value=\"delete\" name=\"dlt" + bookID
						+ "\" onclick=\"deleteSpecificBook(this)\" data-toggle='modal' data-target='#deleteSpecificBook'></td>");
				out.print("</tr>");
			}
			con.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
